// pages/order/order.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:"",
    Sex:"",
    call:"",
    home:"",
    id:0,
    goods:[{
      pic:"cloud://reshan.7265-reshan-1302501212/mall/1.png",
      goods_name:"强国伞",
      money:7990
    },{
      pic:"cloud://reshan.7265-reshan-1302501212/mall/2.png",
      goods_name:"长征书灯",
      money:10800
    },{
      pic:"cloud://reshan.7265-reshan-1302501212/mall/3.png",
      goods_name:"红色记忆手账",
      money:6600
    },{
      pic:"cloud://reshan.7265-reshan-1302501212/mall/4.png",
      goods_name:"叶长埠长尺",
      money:9900
    },{
      pic:"cloud://reshan.7265-reshan-1302501212/mall/5.png",
      goods_name:"建党100周年胶带",
      money:2600
    },{
      pic:"cloud://reshan.7265-reshan-1302501212/mall/6.png",
      goods_name:"红色笔记",
      money:2700
    }]
  },

  /**
   * 购买提交购买产品序号
   */
  formSubmit:function(event){
    console.log(this.data.id)
    console.log(this.data.goods[0].money)
    wx.cloud.callFunction({
      name:'pay',
      data: {
        orderid: '1314'+new Date().getTime(), //订单号要唯一,
        money: this.data.goods[this.data.id].money, //需要支付的金额
        notice:"惹山文化传播有限公司VIP会员"
      },
      success: res=>{
        console.log("支付参数获取成功",res)
        wx.requestPayment({
          nonceStr: res.result.nonceStr,
          package: res.result.package,
          paySign: res.result.paySign,
          timeStamp: res.result.timeStamp,
          signType:'MD5',
          success(res){
            console.log('支付成功',res)
          },
          fail(res){
            console.log('支付失败',res)
          },
          complete(res){
            console.log('支付完成',res)
          }
        })
      },
      fail:res=>{
        console.log("支付参数获取失败",res)
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'data',
      success: (result) => {
        console.log(result.data)
        this.setData({
          name:result.data.name,
          Sex:result.data.Sex,
          call:result.data.call,
          home:result.data.home          
        })
      },
      fail: (res) => {},
      complete: (res) => {},
    })

    // 获取当前的商品id
    console.log("当前商品id为：",options.id);
    this.setData({
      id:options.id
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})